﻿using System;

namespace Ayatta.Contract.Domain
{
    /// <summary>
    /// 拍品
    /// </summary>
    public class ProductAuction : BaseEntity<int>
    {
        /// <summary>
        /// SkuId
        /// </summary>
        public int SkuId { get; set; }

        /// <summary>
        /// 商品Id
        /// </summary> 
        public int ItemId { get; set; }

        /// <summary>
        /// 产品Id
        /// </summary>
        public int ProductId { get; set; }

        /// <summary>
        /// 类目Id
        /// </summary>
        public int CategoryId { get; set; }
        /// <summary>
        /// 根类目Id
        /// </summary>
        public int CategoryRootId { get; set; }

        /// <summary>
        /// 类目字符串
        /// </summary>
        public string CategoryMiddleId { get; set; }

        /// <summary>
        /// 拍品等级
        /// </summary>
        public AuctionLevel Level { get; set; }

        /// <summary>
        /// 拍品分组
        /// </summary>
        public int Group { get; set; }

        /// <summary>
        /// 拍品名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 每次出价消耗金币
        /// </summary>
        public int Price { get; set; }

        /// <summary>
        /// 运费/手续费/附加费
        /// </summary>
        public decimal Adjust { get; set; }

        /// <summary>
        /// 重置秒数
        /// </summary>
        public int Interval { get; set; }

        /// <summary>
        /// 购买价格
        /// </summary>
        public decimal PriceBuy { get; set; }

        /// <summary>
        /// 参考价格
        /// </summary>
        public decimal PriceMarket { get; set; }

        /// <summary>
        /// 成本价格
        /// </summary>
        public decimal PriceCost { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public string StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public string StopTime { get; set; }

        /// <summary>
        /// 上架日期
        /// </summary>
        public DateTime OnlineDate { get; set; }

        /// <summary>
        /// 当出价价格达到AlternatePrice时启用新的重置秒数
        /// </summary>
        public int AlternateInterval { get; set; }

        /// <summary>
        /// 替换价格
        /// </summary>
        public decimal AlternatePrice { get; set; }

        /// <summary>
        /// 是否是0元竞拍拍品
        /// </summary>
        public bool IsZero { get; set; }

        /// <summary>
        /// 是否为自动上架的拍品（拍品被拍走后自动生成一个一样的拍品）
        /// </summary>
        public bool IsAuto { get; set; }

        /// <summary>
        /// 是否为虚拟物品
        /// </summary>
        public bool IsVirtual { get; set; }

        /// <summary>
        /// 是否可补差购买
        /// </summary>
        public bool DiffBuy { get; set; }

        /// <summary>
        /// 可以补差购买数量的条件
        /// </summary>
        public DiffBuyLimit DiffBuyLimit { get; set; }

        /// <summary>
        /// 补差购买数量的条件的值
        /// </summary>
        public int DiffBuyLimitValue { get; set; }

        /// <summary>
        /// 是否可以使用免费拍币
        /// </summary>
        public bool FreeBid { get; set; }

        /// <summary>
        /// 可以使用免费拍币的条件
        /// </summary>
        public FreeBidLimit FreeBidLimit { get; set; }

        /// <summary>
        /// 可以使用免费拍币的条件的值
        /// </summary>
        public int FreeBidLimitValue { get; set; }

        /// <summary>
        /// 是否需要预约
        /// </summary>
        public bool Reservation { get; set; }

        /// <summary>
        /// 兑换积分(0为不可兑换积分)
        /// </summary>
        public int IntegralExchange { get; set; }

        /// <summary>
        /// 图片
        /// </summary>
        public string Picture { get; set; }

        /// <summary>
        /// SKU属性文本
        /// </summary>
        public string PropText { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 商家Id
        /// </summary>
        public int SellerId { get; set; }

        /// <summary>
        /// 当前出价用户Id
        /// </summary>
        public int UserId { get; set; }

        /// <summary>
        /// 当前用户名
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 当前用户昵称
        /// </summary>
        public string Nickname { get; set; }

        /// <summary>
        /// 当前价格
        /// </summary>
        public decimal CurrentPrice { get; set; }

        /// <summary>
        /// 预期成交时间
        /// </summary>
        public DateTime? ExpectedTime { get; set; }

        /// <summary>
        /// 成交时间
        /// </summary>
        public DateTime? FinishedOn { get; set; }

        /// <summary>
        /// IpAddress
        /// </summary>
        public string IpAddress { get; set; }

        /// <summary>
        /// 订单Id
        /// </summary>
        public string OrderId { get; set; }

        /// <summary>
        /// 扩展信息
        /// </summary>
        public string Extra { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public AuctionStatus Status { get; set; }

        /// <summary>
        /// 开始日期时间
        /// </summary>
        public DateTime StartedOn
        {
            get
            {
                DateTime startTime;
                return DateTime.TryParse(StartTime, out startTime) ? startTime : DateTime.Parse("09:00:00");
            }
        }

        /// <summary>
        /// 结束日期时间
        /// </summary>
        public DateTime StoppedOn
        {
            get
            {
                DateTime stopTime;
                return DateTime.TryParse(StopTime, out stopTime) ? stopTime : DateTime.Parse("23:59:59");
            }
        }

        /// <summary>
        /// SKU属性
        /// </summary>
        public string[] PropTexts
        {
            get { return string.IsNullOrEmpty(PropText) ? new string[0] : PropText.Split(';'); }
        }

        /// <summary>
        /// 状态文本
        /// </summary>
        public string StatusText
        {
            get
            {
                var s = string.Empty;
                switch (Status)
                {
                    case AuctionStatus.Normal:
                        s = "正常"; break;
                    case AuctionStatus.Paused:
                        s = "已暂停"; break;
                    case AuctionStatus.Finished:
                        s = "已结束"; break;
                    case AuctionStatus.Deleted:
                        s = "已删除"; break;
                }
                return s;
            }
        }

    }
}
